<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="5" :sm="12">
            <a-form-item label="设备型号">
              <!--<a-input placeholder="请输入账号查询" v-model="queryParam.username"></a-input>-->
              <j-input placeholder="输入设备型号" v-model="queryParam.username"></j-input>
            </a-form-item>
          </a-col>

          <a-col :md="5" :sm="12">
            <a-form-item label="设备名称">
              <!--<a-input placeholder="请输入账号查询" v-model="queryParam.username"></a-input>-->
              <j-input placeholder="输入设备名称" v-model="queryParam.username"></j-input>
            </a-form-item>
          </a-col>

          <a-col :md="5" :sm="12">
            <a-form-item label="规格">
              <!--<a-input placeholder="请输入账号查询" v-model="queryParam.username"></a-input>-->
              <j-input placeholder="输入规格" v-model="queryParam.username"></j-input>
            </a-form-item>
          </a-col>

          <template v-if="toggleSearchStatus">
            <a-col :md="5" :sm="8">
              <a-form-item label="生产商">
                <a-input placeholder="请输入生产商" v-model="queryParam.realname"></a-input>
              </a-form-item>
            </a-col>

            <a-col :md="5" :sm="8">
              <a-form-item label="入库人">
                <a-input placeholder="请输入入库人" v-model="queryParam.phone"></a-input>
              </a-form-item>
            </a-col>

            <a-col :md="5" :sm="8">
              <a-form-item label="入库日期">
                <a-date-picker show-time placeholder="Select Time" @change="onChange" @ok="onOk" />
              </a-form-item>
            </a-col>
          </template>

          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <a-button @click="ruku" type="primary"icon="plus" style="margin-left: 10px;margin-bottom: 2px">添加入库</a-button>
<a-col>
  <a-table
    ref="table"
    bordered
    size="middle"
    rowKey="userId"
    :pagination="ipagination"
    :columns="columns"
    :dataSource="dataSource"
    :loading="loading"
    @change="handleTableChange">
       <span slot="action" slot-scope="text, record">
            <a @click="handleOpen(record)">出售设备</a>
       </span>
  </a-table>
</a-col>
    <a-modal v-model="visible" :width="700" title="入库" @ok="handleOk">
          <a-radio-group v-model="indexStyle" style="margin-left: 20px;">
            <a-radio :value="1">入库</a-radio>
            <a-radio :value="2">已有入库</a-radio>
          </a-radio-group>
        <div v-if="indexStyle==1">
          <a-form layout="inline" :form="form">
            <a-row style="width: 100%;padding-top: 20px;">
              <a-col :span="24 / 2">
                <a-form-item   label="试妆参数" hasFeedback>
                  <a-select style="width: 195px" v-decorator="['type', {}]" placeholder="请选择服务号类型">
                    <a-select-option value="0">没有微信服务号</a-select-option>
                    <a-select-option value="1">JM跨境购</a-select-option>
                    <a-select-option value="2">唯品会合肥城市奥莱服务号</a-select-option>
                    <a-select-option value="3">挑剔小姐MISS PICKY</a-select-option>
                    <a-select-option value="4">美丽旅程</a-select-option>
                    <a-select-option value="5">海蜇优品</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :span="24 / 2">
                <a-form-item  label="设备规格" hasFeedback>
                  <a-input style="width: 195px" placeholder="请输入联系人电话" v-decorator="['gateway', {}]" />
                </a-form-item>
              </a-col>
            </a-row>
            <a-row style="width: 100%;padding-top: 20px;">
              <a-col :span="24 / 2">
                <a-form-item  label="设备型号" hasFeedback>
                  <a-input style="width: 195px" placeholder="请输入联系人电话" v-decorator="['gateway', {}]" />
                </a-form-item>
              </a-col>
              <a-col :span="24 / 2">
                <a-form-item  label="生产厂商" hasFeedback>
                  <a-input style="width: 195px" placeholder="请输入联系人电话" v-decorator="['gateway', {}]" />
                </a-form-item>
              </a-col>
            </a-row>
            <a-row style="width: 100%;padding-top: 20px;">
              <a-col :span="24 / 2">
                <a-form-item  label="设备名称" hasFeedback>
                  <a-input style="width: 195px" placeholder="请输入联系人电话" v-decorator="['gateway', {}]" />
                </a-form-item>
              </a-col>
              <a-col :span="24 / 2">
                <a-form-item  label="入库人员" hasFeedback>
                  <a-input style="width: 195px" placeholder="请输入联系人电话" v-decorator="['gateway', {}]" />
                </a-form-item>
              </a-col>
            </a-row>
            <a-row style="width: 100%;padding-top: 20px;">
              <a-col :span="24 / 2">
                <a-form-item  label="入库数量" hasFeedback>
                  <a-input style="width: 195px" placeholder="请输入联系人电话" v-decorator="['gateway', {}]" />
                </a-form-item>
              </a-col>
              <a-col :span="24 / 2">
                <a-form-item  label="入库日期" hasFeedback>
                  <a-date-picker show-time placeholder="选择时间" @change="onChange" @ok="onOk" >

                  </a-date-picker>
                </a-form-item>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <div v-if="indexStyle==2">
          <a-form layout="inline" :form="form">
          <a-row :gutter="24"style="width: 100%;padding-top: 20px;">
            <a-col :span="12">
              <a-form-item  label="设备名称" hasFeedback>
                <a-select style="width: 195px" v-decorator="['type', {}]" placeholder="请选择">
                  <a-select-option value="0">美妆镜1</a-select-option>
                  <a-select-option value="1">美妆镜2</a-select-option>
                  <a-select-option value="2">美妆镜3</a-select-option>
                  <a-select-option value="3">美妆镜4</a-select-option>
                  <a-select-option value="4">美妆镜5</a-select-option>
                  <a-select-option value="5">美妆镜6</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
            <a-row style="width: 100%;padding-top: 20px;">
              <a-col :span="12">
                <a-form-item  label="入库人员" hasFeedback>
                  <a-input style="width: 195px" placeholder="请输入入库人员" v-decorator="['gateway', {}]" />
                </a-form-item>
              </a-col>
            </a-row>
            <a-row style="width: 100%;padding-top: 20px;">
              <a-col :span="12">
                <a-form-item  label="入库数量" hasFeedback>
                  <a-input style="width: 195px" placeholder="请输入入库数量" v-decorator="['gateway', {}]" />
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter="24"style="width: 100%;padding-top: 20px;">
            <a-col :span="12">
              <a-form-item  label="入库日期" hasFeedback>
                <a-date-picker show-time placeholder="选择时间" @change="onChange" @ok="onOk" />
              </a-form-item>
            </a-col>
          </a-row>
          </a-form>
        </div>
  </a-modal>
<!--  出售设备 modal  -->
    <a-modal v-model="visible2" :width="700" title="出售设备" @ok="handleOk2">
      <a-form layout="inline" :form="form">
        <a-row style="width: 100%;padding-top: 20px;">
          <a-col :span="15">
            <a-form-item  label="设备名称" hasFeedback>
              <a-input style="width: 195px" placeholder="请输入设备名称" v-decorator="['gateway', {}]" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row style="width: 100%;padding-top: 20px;">
          <a-col :span="15">
            <a-form-item  label="出货人员" hasFeedback>
              <a-input style="width: 195px" placeholder="请输入设备名称" v-decorator="['gateway', {}]" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24"style="width: 100%;padding-top: 20px;">
          <a-col :span="15">
            <a-form-item  label="肤质检测型号" hasFeedback>
              <a-select style="width: 170px" v-decorator="['type', {}]" placeholder="请选择">
                <a-select-option value="0">美妆镜1</a-select-option>
                <a-select-option value="1">美妆镜2</a-select-option>
                <a-select-option value="2">美妆镜3</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row style="width: 100%;padding-top: 20px;">
          <a-col :span="15">
            <a-form-item  label="商家名称" hasFeedback>
              <a-select style="width: 195px" v-decorator="['type', {}]" placeholder="请选择">
                <a-select-option value="0">美妆镜1</a-select-option>
                <a-select-option value="1">美妆镜2</a-select-option>
                <a-select-option value="2">美妆镜3</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row style="width: 100%;padding-top: 20px;">
          <a-col :span="15">
            <a-form-item  label="出货数量" hasFeedback>
              <a-input-number  id="inputNumber"size="large" v-model="number_chushou" :min="1" :max="4" @change="onChange_chushou" />
              当前值：{{ number_chushou }}
            </a-form-item>
          </a-col>
        </a-row>
        <a-row style="width: 100%;padding-top: 20px;">
          <a-col :span="15">
            <a-form-item  label="账号编码1" hasFeedback>
              <a-input style="width: 190px" placeholder="请输入入库数量" v-decorator="['gateway', {}]" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row v-if="number_chushou >=2 " style="width: 100%;padding-top: 20px;">
          <a-col :span="15">
            <a-form-item  label="账号编码2" hasFeedback>
              <a-input style="width: 190px" placeholder="请输入入库数量" v-decorator="['gateway', {}]" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row v-if="number_chushou >=3 " style="width: 100%;padding-top: 20px;">
          <a-col :span="15">
            <a-form-item  label="账号编码3" hasFeedback>
              <a-input style="width: 190px" placeholder="请输入入库数量" v-decorator="['gateway', {}]" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row v-if="number_chushou >=4 " style="width: 100%;padding-top: 20px;">
          <a-col :span="15">
            <a-form-item  label="账号编码4" hasFeedback>
              <a-input style="width: 190px" placeholder="请输入入库数量" v-decorator="['gateway', {}]" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24"style="width: 100%;padding-top: 20px;">
          <a-col :span="15">
            <a-form-item  label="出售时间" hasFeedback>
              <a-date-picker show-time placeholder="选择时间" @change="onChange_chushou" @ok="onOk" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-modal>
  </a-card>
</template>

<script>
import { getAction } from '@api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'

export default {
  name: 'equipmentModalA',
  mixins: [JeecgListMixin],
  components: {},
  props: ['value'],
  data() {
    return {
      description: '用户信息',
      cardLoading: true,
      visible: false,
      visible2: false,
      indexStyle:1,
      // 出售设备 数据
      number_chushou:1,
      positionInfo: {},
      columns: [
        {
          title: '#',
          key: 'rowIndex',
          dataIndex: '',
          width: 60,
          align: 'center',
          customRender: (t, r, i) => parseInt(i) + 1
        },
        {
          title: '姓名',
          width: '15%',
          align: 'center',
          dataIndex: 'realname'
        },
        {
          title: '工号',
          width: '',
          align: 'center',
          dataIndex: 'workNo'
        },
        {
          title: '部门',
          width: '',
          align: 'center',
          dataIndex: 'departName'
        },
        {
          title: '职务',
          width: '',
          align: 'center',
          dataIndex: 'post',
          customRender: (text) => (text || '').split(',').map(t => this.positionInfo[t] ? this.positionInfo[t] : t).join(',')
        },
        {
          title: '手机',
          width: '',
          align: 'center',
          dataIndex: 'telephone'
        },
        // {
        //   title: '手机号',
        //   width: '12%',
        //   align: 'center',
        //   dataIndex: 'phone'
        // },
        {
          title: '公司邮箱',
          width: '',
          align: 'center',
          dataIndex: 'email'
        } ,{
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],

      url: {
        list: '/sys/user/queryByOrgCodeForAddressList',
        listByPosition: '/sys/position/list'
      }
    }
  },
  watch: {
    value: {
      immediate: true,
      handler(orgCode) {
        this.dataSource = []
        this.loadData(1, orgCode)
      }
    },
  },
  created() {
    this.queryPositionInfo()
  },
  methods: {

    loadData(pageNum, orgCode) {
      this.loading = true
      if (pageNum === 1) {
        this.ipagination.current = 1
      }
      // update-begin- --- author:wangshuai ------ date:20200102 ---- for:传过来的部门编码为空全查
      if (!orgCode) {
        getAction(this.url.list, {
          ...this.getQueryParams()
        }).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records
            this.ipagination.total = res.result.total
          }
        }).finally(() => {
          this.loading = false
          this.cardLoading = false
        })
        // update-end- --- author:wangshuai ------ date:20200102 ---- for:传过来的部门编码为空全查
      }else{
        //加载数据 若传入参数1则加载第一页的内容
        getAction(this.url.list, {
          orgCode,
          ...this.getQueryParams()
        }).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records
            this.ipagination.total = res.result.total
          }
        }).finally(() => {
          this.loading = false
          this.cardLoading = false
        })
      }
    },
//筛选 选择日期
    onChange(value, dateString) {
      console.log('Selected Time: ', value);
      console.log('Formatted Selected Time: ', dateString);
    },
// 入库
    ruku() {
      this.visible = true;
    },
    handleOk(e) {
      console.log(e);
      this.visible = false;
    },
// 入库结束

//出售设备
    handleOpen(){
      this.visible2 = true;
    },
    handleOk2(e) {
      console.log(e);
      this.visible2 = false;
    },
    onChange_chushou(number_chushou) {
      console.log('changed', number_chushou);
    },

    searchQuery() {
      this.loadData(1, this.value)
    },
    searchReset() {
      this.queryParam = {}
      this.loadData(1, this.value)
    },

    handleTableChange(pagination, filters, sorter) {
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field
        this.isorter.order = 'ascend' === sorter.order ? 'asc' : 'desc'
      }
      this.ipagination = pagination
      this.loadData(null, this.value)
    },

    // 查询职务信息
    queryPositionInfo() {
      getAction(this.url.listByPosition, { pageSize: 99999 }).then(res => {
        if (res.success) {
          let positionInfo = {}
          res.result.records.forEach(record => {
            positionInfo[record['code']] = record['name']
          })
          this.positionInfo = positionInfo
        }
      })
    }

  }
}
</script>
<style>
.j-address-list-right-card-box .ant-table-placeholder {
  min-height: 46px;
}
</style>
<style scoped>
.j-address-list-right-card-box {
  height: 100%;
  min-height: 300px;
}
.table-page-search-wrapper {
  margin-top: 0px;
  margin-bottom: 2px;
  padding-top: 0px;
}
</style>